/*
 * Copyright (c) 2024 vitasystems GmbH
 *
 * This file is part of project EHRbase Migration Tool
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.ehrbase.migration.importer.v4.jooq.pg.tables;

import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.function.Function;
import org.ehrbase.migration.importer.v4.jooq.pg.Keys;
import org.ehrbase.migration.importer.v4.jooq.pg.tables.records.CompDataHistoryRecord;
import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.Function14;
import org.jooq.JSONB;
import org.jooq.Name;
import org.jooq.Record;
import org.jooq.Records;
import org.jooq.Row14;
import org.jooq.Schema;
import org.jooq.SelectField;
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.TableOptions;
import org.jooq.UniqueKey;
import org.jooq.impl.DSL;
import org.jooq.impl.SQLDataType;
import org.jooq.impl.TableImpl;

/**
 * This class is generated by jOOQ.
 */
@SuppressWarnings({"all", "unchecked", "rawtypes", "this-escape"})
public class CompDataHistory extends TableImpl<CompDataHistoryRecord> {

    private static final long serialVersionUID = 1L;

    /**
     * The reference instance of <code>ehr.comp_data_history</code>
     */
    public static final CompDataHistory COMP_DATA_HISTORY = new CompDataHistory();

    /**
     * The class holding records for this type
     */
    @Override
    public Class<CompDataHistoryRecord> getRecordType() {
        return CompDataHistoryRecord.class;
    }

    /**
     * The column <code>ehr.comp_data_history.vo_id</code>.
     */
    public final TableField<CompDataHistoryRecord, UUID> VO_ID =
            createField(DSL.name("vo_id"), SQLDataType.UUID.nullable(false), this, "");

    /**
     * The column <code>ehr.comp_data_history.num</code>.
     */
    public final TableField<CompDataHistoryRecord, Integer> NUM =
            createField(DSL.name("num"), SQLDataType.INTEGER.nullable(false), this, "");

    /**
     * The column <code>ehr.comp_data_history.citem_num</code>.
     */
    public final TableField<CompDataHistoryRecord, Integer> CITEM_NUM =
            createField(DSL.name("citem_num"), SQLDataType.INTEGER, this, "");

    /**
     * The column <code>ehr.comp_data_history.rm_entity</code>.
     */
    public final TableField<CompDataHistoryRecord, String> RM_ENTITY =
            createField(DSL.name("rm_entity"), SQLDataType.CLOB.nullable(false), this, "");

    /**
     * The column <code>ehr.comp_data_history.entity_concept</code>.
     */
    public final TableField<CompDataHistoryRecord, String> ENTITY_CONCEPT =
            createField(DSL.name("entity_concept"), SQLDataType.CLOB, this, "");

    /**
     * The column <code>ehr.comp_data_history.entity_name</code>.
     */
    public final TableField<CompDataHistoryRecord, String> ENTITY_NAME =
            createField(DSL.name("entity_name"), SQLDataType.CLOB, this, "");

    /**
     * The column <code>ehr.comp_data_history.entity_attribute</code>.
     */
    public final TableField<CompDataHistoryRecord, String> ENTITY_ATTRIBUTE =
            createField(DSL.name("entity_attribute"), SQLDataType.CLOB, this, "");

    /**
     * The column <code>ehr.comp_data_history.entity_path</code>.
     */
    public final TableField<CompDataHistoryRecord, String> ENTITY_PATH =
            createField(DSL.name("entity_path"), SQLDataType.CLOB.nullable(false), this, "");

    /**
     * The column <code>ehr.comp_data_history.entity_path_cap</code>.
     */
    public final TableField<CompDataHistoryRecord, String> ENTITY_PATH_CAP =
            createField(DSL.name("entity_path_cap"), SQLDataType.CLOB.nullable(false), this, "");

    /**
     * The column <code>ehr.comp_data_history.entity_idx</code>.
     */
    public final TableField<CompDataHistoryRecord, String> ENTITY_IDX =
            createField(DSL.name("entity_idx"), SQLDataType.CLOB.nullable(false), this, "");

    /**
     * The column <code>ehr.comp_data_history.entity_idx_cap</code>.
     */
    public final TableField<CompDataHistoryRecord, String> ENTITY_IDX_CAP =
            createField(DSL.name("entity_idx_cap"), SQLDataType.CLOB.nullable(false), this, "");

    /**
     * The column <code>ehr.comp_data_history.entity_idx_len</code>.
     */
    public final TableField<CompDataHistoryRecord, Integer> ENTITY_IDX_LEN =
            createField(DSL.name("entity_idx_len"), SQLDataType.INTEGER.nullable(false), this, "");

    /**
     * The column <code>ehr.comp_data_history.data</code>.
     */
    public final TableField<CompDataHistoryRecord, JSONB> DATA =
            createField(DSL.name("data"), SQLDataType.JSONB.nullable(false), this, "");

    /**
     * The column <code>ehr.comp_data_history.sys_version</code>.
     */
    public final TableField<CompDataHistoryRecord, Integer> SYS_VERSION =
            createField(DSL.name("sys_version"), SQLDataType.INTEGER.nullable(false), this, "");

    private CompDataHistory(Name alias, Table<CompDataHistoryRecord> aliased) {
        this(alias, aliased, null);
    }

    private CompDataHistory(Name alias, Table<CompDataHistoryRecord> aliased, Field<?>[] parameters) {
        super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table());
    }

    /**
     * Create an aliased <code>ehr.comp_data_history</code> table reference
     */
    public CompDataHistory(String alias) {
        this(DSL.name(alias), COMP_DATA_HISTORY);
    }

    /**
     * Create an aliased <code>ehr.comp_data_history</code> table reference
     */
    public CompDataHistory(Name alias) {
        this(alias, COMP_DATA_HISTORY);
    }

    /**
     * Create a <code>ehr.comp_data_history</code> table reference
     */
    public CompDataHistory() {
        this(DSL.name("comp_data_history"), null);
    }

    public <O extends Record> CompDataHistory(Table<O> child, ForeignKey<O, CompDataHistoryRecord> key) {
        super(child, key, COMP_DATA_HISTORY);
    }

    @Override
    public Schema getSchema() {
        return aliased() ? null : org.ehrbase.migration.importer.v4.jooq.pg.Ehr.EHR;
    }

    @Override
    public UniqueKey<CompDataHistoryRecord> getPrimaryKey() {
        return Keys.COMP_HISTORY_PKEY;
    }

    @Override
    public List<ForeignKey<CompDataHistoryRecord, ?>> getReferences() {
        return Arrays.asList(Keys.COMP_DATA_HISTORY__COMP_DATA_HISTORY_VO_ID_SYS_VERSION_FKEY);
    }

    private transient CompVersionHistory _compVersionHistory;

    /**
     * Get the implicit join path to the <code>ehr.comp_version_history</code>
     * table.
     */
    public CompVersionHistory compVersionHistory() {
        if (_compVersionHistory == null)
            _compVersionHistory =
                    new CompVersionHistory(this, Keys.COMP_DATA_HISTORY__COMP_DATA_HISTORY_VO_ID_SYS_VERSION_FKEY);

        return _compVersionHistory;
    }

    @Override
    public CompDataHistory as(String alias) {
        return new CompDataHistory(DSL.name(alias), this);
    }

    @Override
    public CompDataHistory as(Name alias) {
        return new CompDataHistory(alias, this);
    }

    @Override
    public CompDataHistory as(Table<?> alias) {
        return new CompDataHistory(alias.getQualifiedName(), this);
    }

    /**
     * Rename this table
     */
    @Override
    public CompDataHistory rename(String name) {
        return new CompDataHistory(DSL.name(name), null);
    }

    /**
     * Rename this table
     */
    @Override
    public CompDataHistory rename(Name name) {
        return new CompDataHistory(name, null);
    }

    /**
     * Rename this table
     */
    @Override
    public CompDataHistory rename(Table<?> name) {
        return new CompDataHistory(name.getQualifiedName(), null);
    }

    // -------------------------------------------------------------------------
    // Row14 type methods
    // -------------------------------------------------------------------------

    @Override
    public Row14<
                    UUID,
                    Integer,
                    Integer,
                    String,
                    String,
                    String,
                    String,
                    String,
                    String,
                    String,
                    String,
                    Integer,
                    JSONB,
                    Integer>
            fieldsRow() {
        return (Row14) super.fieldsRow();
    }

    /**
     * Convenience mapping calling {@link SelectField#convertFrom(Function)}.
     */
    public <U> SelectField<U> mapping(
            Function14<
                            ? super UUID,
                            ? super Integer,
                            ? super Integer,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super Integer,
                            ? super JSONB,
                            ? super Integer,
                            ? extends U>
                    from) {
        return convertFrom(Records.mapping(from));
    }

    /**
     * Convenience mapping calling {@link SelectField#convertFrom(Class,
     * Function)}.
     */
    public <U> SelectField<U> mapping(
            Class<U> toType,
            Function14<
                            ? super UUID,
                            ? super Integer,
                            ? super Integer,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super Integer,
                            ? super JSONB,
                            ? super Integer,
                            ? extends U>
                    from) {
        return convertFrom(toType, Records.mapping(from));
    }
}
